/**
 * @desc 判断鼠标从哪个方向进入和离开容器
 * @param { Node } elem
 * @param { Event Object } e
 * @return { Number } 0, 1, 2, 3 => 上，右，下，左
 */
export function mouseDirection (elem, e) {
  const rect = elem.getBoundingClientRect();
  const w = rect.width;
  const h = rect.height;
  const x = (e.pageX - rect.left - (w / 2)) * (w > h ? (h / w) : 1);
  const y = (e.pageY - rect.top - (h / 2)) * (h > w ? (w / h) : 1);
  return Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
}
